package com.dongdongshop.controller;

import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrankService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("brand")
public class BrandController {

    @DubboReference
    private BrankService brankService;

    @RequestMapping("brandList")
    public String brandList(){
        return "admin/brand";
    }

    @RequestMapping("findList")
    @ResponseBody
    public Result findList(@RequestParam(defaultValue = "1")Integer pageNum,
                           @RequestParam(defaultValue = "3")Integer pageSize){
        Page<TbBrand> page = brankService.findList(pageNum,pageSize);
        return Result.ok().setData(page);
    }

    @RequestMapping("selectById")
    @ResponseBody
    public Result selectById(Long id){
        TbBrand tbBrand = brankService.selectById(id);
        return Result.response(ResultEnum.SUCCESS).setData(tbBrand);
    }


    @RequestMapping("UpdateInfo")
    @ResponseBody
    public Result UpdateInfo(TbBrand tbBrand){
        Integer i = brankService.UpdateInfo(tbBrand);
        return Result.response(ResultEnum.SUCCESS);
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public Result add(TbBrand tbBrand){
        Integer i = brankService.addInfo(tbBrand);
        return Result.response(ResultEnum.SUCCESS);
    }

    @RequestMapping("deleteInfo")
    @ResponseBody
    public Result deleteInfo(Integer[] ids){
        Integer i = brankService.deleteInfo(ids);
        return Result.ok();
    }
}
